﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using System.Xml;

using PowerCreator.LMS.Course.Entity;
using PowerCreator.LMS.Common.Script;
using PowerCreator.LMS.Web.Course;
using PowerCreator.LMS.Web;
using PowerCreator.LMS.Common.Upload;
using PowerCreator.LMS.Common.Utils;
using PowerCreator.LMS.Grade.Entity;
using PowerCreator.LMS.Web.Grade;
using PowerCreator.LMS.ASF2JPG;

public partial class sysadmin_CourseManager_AddResourceInfo : PowerCreator.LMS.Web.Base.BasePage
{
    Course opCourse = new Course();
    //从课件content.xml文件中读取到的参数
    protected string _guid = "";
    protected DateTime _starttime = DateTime.MinValue;
    protected string _videotime = "";
    private ASF2JPG opAsf2Jpg = new ASF2JPG();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //资源文件类型别，1课件资源，2考试资源
            ViewState["CoursersClass"] = "1";
            //资源添加方式，upload 上传方式,addnew普通方式
            ViewState["AddResourceType"] = "addnew";

            ViewState["ResourceType:OpTypeID"] = "0"; //需要编辑的资源分类ID
            ViewState["ResourceType:OpType"] = "add";//add|edit|del三种方式

            InitPage();
            BinderSysResourceType();
            BinderCourseResourceType(); 
            BinderResourceTypeRPT();

            if (Request.QueryString["CoursersClass"] != null)
            {
                string coursersclass = Request.QueryString["CoursersClass"].ToString();
                ViewState["CoursersClass"] = coursersclass;
            }
            if (Request.QueryString["AddResourceType"] != null)
            {
                string addresourcetype = Request.QueryString["AddResourceType"].ToString();
                ViewState["AddResourceType"] = addresourcetype;
            }
            //课程ID
            string courseid = Request.QueryString["CourseID"].ToString();
            ViewState["CourseID"] = courseid;

            lab_CourseName.Text = opCourse.LoadVOTCourse(int.Parse(ViewState["CourseID"].ToString())).CourseName;


            if (ViewState["AddResourceType"].ToString() == "upload")
            {
                //string url = "AddResourceInfo.aspx?AddResourceType=upload&CourseID=" + ddl_Course.SelectedValue.ToString() + "&SysResourceType=" + ddl_ResourceType.SelectedValue.ToString() + "&dir=" + txt_NewDirectiory.Text.ToString() + "&fileName=" + fileName;
                string sysresourcetype = Request.QueryString["SysResourceType"].ToString();
                string dir = Request.QueryString["dir"].ToString();
                string filename = Request.QueryString["fileName"].ToString();
                ddl_ResourceType.SelectedValue = "5";
                ddl_ResourceClass.SelectedValue = sysresourcetype;
                ddl_ResourceClass.Enabled = false;

                if (!dir.StartsWith("/"))
                {
                    dir = "/" + dir;
                }
                if (!dir.EndsWith("/"))
                {
                    dir += "/";
                }
                txt_Url.Value = dir;
                txt_Url.Disabled = true;

                txt_EntryFileName.Value = filename;

                //是否解压
                if (Convert.ToInt16(SysResourceType.PowerCreator).ToString() == sysresourcetype)
                {
                    string path = Request.QueryString["fullpath"].ToString();
                    txt_EntryFileName.Value = "content.htm";
                }
                txt_EntryFileName.Disabled = true;
            }
        }
    }

    protected override void InitPage()
    {
        lbl_InfoTitle_AddVirtual.Text = GetLanageValueByKey("lbl_AddResourceInfo_InfoTitle", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_ResourceName.Text = GetLanageValueByKey("lbl_AddResourceInfo_ResourceName", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_ResourceClass.Text = GetLanageValueByKey("lbl_AddResourceInfo_ResourceClass", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_CourseName.Text = GetLanageValueByKey("lbl_AddResourceInfo_CourseName", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_VideoTime.Text = GetLanageValueByKey("lbl_AddResourceInfo_VideoTime", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_AuthorName.Text = GetLanageValueByKey("lbl_AddResourceInfo_AuthorName", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_CoursersRestpID.Text = GetLanageValueByKey("lbl_AddResourceInfo_CoursersRestpID", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_Remark.Text = GetLanageValueByKey("lbl_AddResourceInfo_Remark", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_advert.Text = GetLanageValueByKey("lbl_AddResourceInfo_advert", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_advert_English.Text = GetLanageValueByKey("lbl_AddResourceInfo_advert_English", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_Url.Text = GetLanageValueByKey("lbl_AddResourceInfo_Url", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_advert_url.Text = GetLanageValueByKey("lbl_AddResourceInfo_advert_url", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_EntryFileName.Text = GetLanageValueByKey("lbl_AddResourceInfo_EntryFileName", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_advert_htm.Text = GetLanageValueByKey("lbl_AddResourceInfo_advert_htm", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_vt_format.Text = "<span style=\"color: #ff0033\">*</span><span class=\"red\"></span>("+GetLanageValueByKey("AddResourceInfo_lbl_l1_2", PowerCreator.LMS.Language.LanagetItemType.Page)+")";

        lbl_InfoTitle.Text = GetLanageValueByKey("lbl_AddCourseResourceType_InfoTitle", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_CourseResourceType.Text = GetLanageValueByKey("lbl_AddCourseResourceType_CourseResourceType", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_CourseResourceType1.Text = GetLanageValueByKey("lbl_AddCourseResourceType_CourseResourceType1", PowerCreator.LMS.Language.LanagetItemType.Page);
        btn_addresourcetype.Text = GetLanageValueByKey("btn_AddCourseResourceType_Save", PowerCreator.LMS.Language.LanagetItemType.Page);
       // btn_Reset.Text = GetLanageValueByKey("btn_AddCourseResourceType_Reset", PowerCreator.LMS.Language.LanagetItemType.Page);
        rfv_txt_ResourceName.ErrorMessage = GetLanageValueByKey("AddResourceInfo_msg_m1", PowerCreator.LMS.Language.LanagetItemType.Page);
        RequiredFieldValidator1.ErrorMessage = GetLanageValueByKey("AddResourceInfo_msg_m2", PowerCreator.LMS.Language.LanagetItemType.Page);
        RequiredFieldValidator2.ErrorMessage = GetLanageValueByKey("AddResourceInfo_msg_m3", PowerCreator.LMS.Language.LanagetItemType.Page);
        
        //btn_AddNewCoursersRest.Text = GetLanageValueByKey("btn_AddResourceInfo_AddNewCoursersRest", PowerCreator.LMS.Language.LanagetItemType.Page);
        btnTest.Value = GetLanageValueByKey("btn_AddResourceInfo_Test", PowerCreator.LMS.Language.LanagetItemType.Page);
        btnPreview.Text = GetLanageValueByKey("btn_AddResourceInfo_Preview", PowerCreator.LMS.Language.LanagetItemType.Page);
        btn_Save.Value = GetLanageValueByKey("btn_AddResourceInfo_Save", PowerCreator.LMS.Language.LanagetItemType.Page);
        btn_Reset.Text = GetLanageValueByKey("btn_AddResourceInfo_Reset", PowerCreator.LMS.Language.LanagetItemType.Page);

        base.InitPage();
    }
    private void BinderCourseResourceType()
    {
        string search = "";
        DataTable dt = opCourse.QueryResourceType(search);
        ArrayList list = opCourse.GetResourceTypeTree(dt);
        ddl_CoursersRestpID.DataSource = list;
        ddl_CoursersRestpID.DataTextField = "Text";
        ddl_CoursersRestpID.DataValueField = "Value";
        ddl_CoursersRestpID.DataBind();
    }

    private void BinderResourceTypeRPT()
    {
        string search = "";
        DataTable dt = opCourse.QueryResourceType(search);
        ArrayList list = opCourse.GetResourceTypeTree(dt);
        rpt_RestpName.DataSource = list;
        rpt_RestpName.DataBind();

        for (int i = 0; i < rpt_RestpName.Items.Count; i++)
        {
            Button btnadd = (Button)rpt_RestpName.Items[i].FindControl("btn_Add");
            btnadd.Text = GetLanageValueByKey("btn_AddNew", PowerCreator.LMS.Language.LanagetItemType.Page);
            Button btn_Editor = (Button)rpt_RestpName.Items[i].FindControl("btn_Editor");
            btn_Editor.Text = GetLanageValueByKey("ManagerRole_gv_lnk_o1", PowerCreator.LMS.Language.LanagetItemType.Page);
            Button Button1 = (Button)rpt_RestpName.Items[i].FindControl("Button1");
            Button1.Text = GetLanageValueByKey("ManagerRole_gv_lnk_o2", PowerCreator.LMS.Language.LanagetItemType.Page);
        }

        ddl_ResourceType.DataSource = list;
        ddl_ResourceType.DataTextField = "Text";
        ddl_ResourceType.DataValueField = "Value";
        ddl_ResourceType.DataBind();
        ListItem li = new ListItem();
        li.Text = GetLanageValueByKey("AddTrainProjectType_db_d1", PowerCreator.LMS.Language.LanagetItemType.Page);
        li.Value = "0";
        ddl_ResourceType.Items.Insert(0, li);
    }
    private void BinderSysResourceType()
    {

        ListItem li1 = new ListItem();
        li1.Text = GetLanageValueByKey("Resource_Type1", PowerCreator.LMS.Language.LanagetItemType.Page);
        li1.Value = "1";
        ddl_ResourceClass.Items.Add(li1);
        ListItem li2 = new ListItem();
        li2.Text = GetLanageValueByKey("Resource_Type2", PowerCreator.LMS.Language.LanagetItemType.Page);
        li2.Value = "2";
        ddl_ResourceClass.Items.Add(li2);
        ListItem li3 = new ListItem();
        li3.Text = GetLanageValueByKey("Resource_Type3", PowerCreator.LMS.Language.LanagetItemType.Page);
        li3.Value = "3";
        ddl_ResourceClass.Items.Add(li3);
        ListItem li4 = new ListItem();
        li4.Text = GetLanageValueByKey("Resource_Type4", PowerCreator.LMS.Language.LanagetItemType.Page);
        li4.Value = "4";
        ddl_ResourceClass.Items.Add(li4);
        ListItem li5 = new ListItem();
        li5.Text = GetLanageValueByKey("Resource_Type5", PowerCreator.LMS.Language.LanagetItemType.Page);
        li5.Value = "5";
        ddl_ResourceClass.Items.Add(li5);
    }

    protected void ddl_CoursersRestpID_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddl_CoursersRestpID.SelectedValue == "1" || ddl_CoursersRestpID.SelectedValue == "2" || ddl_CoursersRestpID.SelectedValue == "3")
        {
            ddl_ResourceClass.Enabled = true;
            txt_Url.Visible = true;
            txt_EntryFileName.Visible = true;
            txt_VideoTime.Visible = true;
            lbl_VideoTime.Visible = true;
            lbl_vt_format.Visible = true;
            txt_AuthorName.Visible = true;
            lbl_AuthorName.Visible = true;
            tr_1.Visible = true;
            tr_2.Visible = true;
            tr_3.Visible = true;


            ddl_ResourceClass.Items.Clear();

            ListItem li1 = new ListItem();
            li1.Text = GetLanageValueByKey("Resource_Type1", PowerCreator.LMS.Language.LanagetItemType.Page);
            li1.Value = "1";
            ddl_ResourceClass.Items.Add(li1);
            ListItem li2 = new ListItem();
            li2.Text = GetLanageValueByKey("Resource_Type2", PowerCreator.LMS.Language.LanagetItemType.Page);
            li2.Value = "2";
            ddl_ResourceClass.Items.Add(li2);
            ListItem li4 = new ListItem();
            li4.Text = GetLanageValueByKey("Resource_Type4", PowerCreator.LMS.Language.LanagetItemType.Page);
            li4.Value = "4";
            ddl_ResourceClass.Items.Add(li4);
            ListItem li5 = new ListItem();
            li5.Text = GetLanageValueByKey("Resource_Type5", PowerCreator.LMS.Language.LanagetItemType.Page);
            li5.Value = "5";
            ddl_ResourceClass.Items.Add(li5);
        }
        else if (ddl_CoursersRestpID.SelectedValue == "5")
        {
            ddl_ResourceClass.Items.Clear();

            txt_Url.Visible = true;
            txt_EntryFileName.Visible = true;
            txt_VideoTime.Visible = true;
            lbl_VideoTime.Visible = true;
            lbl_vt_format.Visible = true;
            txt_AuthorName.Visible = true;
            lbl_AuthorName.Visible = true;
            tr_1.Visible = true;
            tr_2.Visible = true;
            tr_3.Visible = true;


            ListItem li3 = new ListItem();
            li3.Text = GetLanageValueByKey("Resource_Type3", PowerCreator.LMS.Language.LanagetItemType.Page);
            li3.Value = "3";
            ddl_ResourceClass.Items.Add(li3);
        }
        else if (ddl_CoursersRestpID.SelectedValue == "4")
        {
            ddl_ResourceClass.Enabled = false;
            txt_Url.Value = "Null";
            txt_Url.Visible = false;
            txt_EntryFileName.Value = "Null";
            txt_EntryFileName.Visible = false;
            txt_VideoTime.Value = "00:00:00";
            txt_AuthorName.Value = "Null";
            txt_AuthorName.Visible = false;
            lbl_AuthorName.Visible = false;
            txt_VideoTime.Visible = false;
            lbl_VideoTime.Visible = false;
            lbl_vt_format.Visible = false;
            tr_1.Visible = false;
            tr_2.Visible = false;
            tr_3.Visible = false;

        }
    }
    private bool CheckPageData()
    {
        if (string.IsNullOrEmpty(ddl_CoursersRestpID.SelectedValue.ToString()))
        {
            lbl_addresourceinfo_msg_courseesrestpid.Text = GetLanageValueByKey("AddResourceInfo_msg_m4", PowerCreator.LMS.Language.LanagetItemType.Page);
            return false;
        }
        string search = string.Format("ResourceName='{0}'", txt_ResourceName.Value);
        if (opCourse.QueryResourceCount(search) != 0)
        {
            lbl_addresourceinfo_msg_resourcename.Text = GetLanageValueByKey("AddResourceInfo_msg_m5", PowerCreator.LMS.Language.LanagetItemType.Page);
            return false;
        }
        return true;
    }
    protected void btnTest_ServerClick(object sender, EventArgs e)
    {
        string path = Server.MapPath(WebUtils.WebRoot + txt_Url.Value + txt_EntryFileName.Value);
        if (System.IO.File.Exists(path))
        {
            lbl_addressourceinfo_filepath.Text = GetLanageValueByKey("AddResourceInfo_msg_m6", PowerCreator.LMS.Language.LanagetItemType.Page);
        }
        else
        {
            lbl_addressourceinfo_filepath.Text = GetLanageValueByKey("AddResourceInfo_msg_m7", PowerCreator.LMS.Language.LanagetItemType.Page) + path;
        }
    }
    protected void btnPreview_Click(object sender, EventArgs e)
    {
        string url = WebUtils.WebRoot + txt_Url.Value + txt_EntryFileName.Value;
        Script.NewOpenURL(url,"testfileurl");
    }

    protected void btnReset_Click(object sender, EventArgs e)
    {
        string url = "ResourceList.aspx?CourseID=" + ViewState["CourseID"].ToString();
        Script.RedirectURL(url);
    }
    protected void btn_Save_ServerClick(object sender, EventArgs e)
    {
        if (!CheckPageData()) return;
        
        VOTResource voResource = new VOTResource();
        voResource.ResourceAuthor = txt_AuthorName.Value;
        voResource.ResourceClass = int.Parse(ddl_ResourceClass.SelectedValue.ToString());
        voResource.ResourceClickNum = 0;
        voResource.ResourceDescription = FreeTextBox1.Text;
        voResource.ResourceEntry = txt_EntryFileName.Value;
        voResource.ResourceIsRecommend = 0;
        voResource.ResourceLastVisitTime = DateTime.Now;
        voResource.ResourceMmsUpdateState = false;
        voResource.ResourceName = txt_ResourceName.Value;
        voResource.ResourceUrl = txt_Url.Value;
        if (!voResource.ResourceUrl.StartsWith("/"))
        {
            voResource.ResourceUrl = "/" + voResource.ResourceUrl;
        }
        if (!voResource.ResourceUrl.EndsWith("/"))
        {
            voResource.ResourceUrl += "/";
        }
        voResource.ResourceVideoTime = opCourse.GetSecond(txt_VideoTime.Value.Trim());
        voResource.ResourseState = 0;
        voResource.ResourceDownLoadFileName = "";

        VOTResourceType voResourceType = new VOTResourceType();
        voResourceType.RestpID = int.Parse(ddl_CoursersRestpID.SelectedValue.ToString());
        voResourceType.RestpName = ddl_CoursersRestpID.SelectedItem.Text;

        CreatedByInfo cinfo = GetCreatedByInfo();
        VOTOCourse voCourse = opCourse.LoadVOTCourse(int.Parse(ViewState["CourseID"].ToString()));

        if (opCourse.AddCourseResource(voResource, voResourceType, cinfo, voCourse,null,null,CoursersClass.Courseware))
        {
            
            if (voResource.ResourceClass == 1)
            {
                //不在同一台服务器的话会有问题
                try
                {
                    //视频文件生成缩略图
                    string filePath = Server.MapPath(voResource.ResourceUrl);
                    opAsf2Jpg.LMSGetEveryJpg(filePath);
                }
                catch
                { }

                //评估模块相关修改  H:\課件虛擬目錄\course\0\CW20100723170304
                // ReadFile(HttpContext.Current.Server.MapPath(vo.ResourceUrl) + "\\"+"content.xml");
                string rid = "0";
                DataTable dt = new DataTable();
                PowerCreator.LMS.ViewQuery.ViewQuery op = new PowerCreator.LMS.ViewQuery.ViewQuery();
                dt = op.Query("select top 1 ResourceID from TResource where ResourceName='" + voResource.ResourceName + "'");
                if (dt.Rows.Count == 1)
                {
                    rid = dt.Rows[0][0].ToString();
                    string xmlPath = HttpContext.Current.Server.MapPath(WebUtils.WebRoot + voResource.ResourceUrl + "\\" + "content.xml");
                    if (System.IO.File.Exists(xmlPath))
                    {
                        ReadFile(xmlPath);
                        //ReadFile("H:\\課件虛擬目錄\\course\\0\\CW20100723170304\\" + "content.xml");
                        if (_guid != null)
                            UpdateGradeResourceID(int.Parse(rid));
                        //如果设置为检查则根据content.xml中的时间修改记录
                        if (ConfigurationManager.AppSettings["CheckResourceVideoTime"].ToString() == "1")
                            UpdateResourceVideotime(int.Parse(rid));
                    }
                }
            }
            else if (voResource.ResourceClass == 2)
            {
                //不在同一台服务器的话会有问题
                try
                {
                    //视频文件生成缩略图
                    string filePath = Server.MapPath(voResource.ResourceUrl);
                    opAsf2Jpg.LMSGetEveryJpg(filePath);
                }
                catch
                { }
            }
            string url = "ResourceList.aspx?CourseID=" + ViewState["CourseID"].ToString();
            Script.RedirectURL(url);
        }
    }
    protected void btn_AddNewCoursersRest_Click(object sender, EventArgs e)
    {
        string url = "AddCourseResourceType.aspx?CourseID=" + ViewState["CourseID"].ToString();
        Script.RedirectURL(url);
    }

    protected void btn_Save_Click(object sender, EventArgs e)
    {

    }

    private bool CheckResourceTypePageData()
    {
        if (string.IsNullOrEmpty(txt_CourseResourceType.Value))
        {
            lbl_addcourseresourcetype_msg_courseresourcetypename.Text = GetLanageValueByKey("AddResourceInfo_msg_m8", PowerCreator.LMS.Language.LanagetItemType.Page);
            return false;
        }
        string search = string.Format("RestpName='{0}'", txt_CourseResourceType.Value);

        if (ViewState["ResourceType:OpType"].ToString() == "edit")
        {
            search += " and RestpID <> " + ViewState["ResourceType:OpTypeID"].ToString();
        }

        if (opCourse.QueryResourceTypeCount(search) != 0)
        {
            lbl_addcourseresourcetype_msg_courseresourcetypename.Text = GetLanageValueByKey("AddResourceInfo_msg_m9", PowerCreator.LMS.Language.LanagetItemType.Page);
            return false;
        }
        return true;
    }
    protected void btn_addresourcetype_Click(object sender, EventArgs e)
    {
        if (!CheckResourceTypePageData())
        {
            Page.ClientScript.RegisterStartupScript(Page.GetType(), "showmy1", "<script>showFloat()</script>");
            return;
        }

        VOTResourceType vo = new VOTResourceType();
        vo.RestpName = txt_CourseResourceType.Value;
        vo.RestpFatherID = int.Parse(ddl_ResourceType.SelectedValue.ToString());
        vo.RestpIsTop = 0;
        vo.RestpOrderBy = 0;
        vo.RestpLayer = opCourse.QueryResourceTypeLayer(vo.RestpFatherID);


        if (ViewState["ResourceType:OpType"].ToString() == "add")
        {
            if (opCourse.AddResourceType(vo))
            {
                BinderCourseResourceType();
                BinderResourceTypeRPT();
            }
        }
        else if (ViewState["ResourceType:OpType"].ToString() == "edit")
        {
            vo.RestpID = int.Parse(ViewState["ResourceType:OpTypeID"].ToString());
            if (opCourse.UpdateResourceType(vo))
            {
                BinderCourseResourceType();
                BinderResourceTypeRPT();
            }
        }
    }

    protected void rpt_RestpName_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        ViewState["ResourceType:OpTypeID"] = e.CommandArgument.ToString();
        if (e.CommandName == "btnadd")
        {
            ViewState["ResourceType:OpType"] = "add";
            ddl_ResourceType.SelectedValue = ViewState["ResourceType:OpTypeID"].ToString();
            txt_CourseResourceType.Value = "";
        }
        else if (e.CommandName == "btnedit")
        {
            ViewState["ResourceType:OpType"] = "edit";
            VOTResourceType vo = opCourse.LoadResourceType(int.Parse(ViewState["ResourceType:OpTypeID"].ToString()));
            ddl_ResourceType.SelectedValue = vo.RestpFatherID.ToString();
            txt_CourseResourceType.Value = vo.RestpName;
        }
        else if (e.CommandName == "btndel")
        {
            ViewState["ResourceType:OpType"] = "del";
            int count = opCourse.QueryResourceTypeParent(int.Parse(ViewState["ResourceType:OpTypeID"].ToString()));
            if (count > 1)
            {
                Label lblmsg = (Label)e.Item.FindControl("lbl_msg_description");
                //lblmsg.Text = "资源分类下有子分类，不允许删除该分类信息!";
                lblmsg.Text = GetLanageValueByKey("AddResourceInfo_gv_m1", PowerCreator.LMS.Language.LanagetItemType.Page);
            }
        }
        Page.ClientScript.RegisterStartupScript(Page.GetType(), "showmy1", "<script>showFloat()</script>");
    }



    private void ReadFile(string filepath)
    {
        XmlTextReader reader = new XmlTextReader(filepath);
        reader.WhitespaceHandling = WhitespaceHandling.None;

        XmlDocument xmlDoc = new XmlDocument();

        //将文件加载到XmlDocument对象中

        xmlDoc.Load(reader);

        //关闭连接

        reader.Close();


        XmlNode xnod = xmlDoc.DocumentElement;
        XmlNode xnodWorking;
        if (xnod.Name == "DOCUMENT")
        {
            //如果还有子节点，就递归地调用这个程序

            if (xnod.HasChildNodes)
            {
                xnodWorking = xnod.FirstChild;

                while (xnodWorking != null)
                {
                    if (xnodWorking.Name == "DATETIME")
                    {
                        string time = xnodWorking.FirstChild.Value;
                        _starttime = DateTime.Parse(time);
                    }
                    else if (xnodWorking.Name == "GUID")
                    {
                        _guid = xnodWorking.FirstChild.Value;
                    }
                    else if (xnodWorking.Name == "DURATION")
                    {
                        _videotime = xnodWorking.FirstChild.Value;
                    }

                    xnodWorking = xnodWorking.NextSibling;
                }

            }

        }

    }

    private void UpdateGradeResourceID(int ResourceID)
    {
        VOTGrade vo = new VOTGrade();
        GradeManager opGrade = new GradeManager();
        DataTable dt = new DataTable();
        string sql = "FKGradeContentGuid='" + _guid + "' and FKGradeResourceID is null";
        dt = opGrade.QueryGrade(sql);
        if (dt.Rows.Count > 0)
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                vo.GradeID = int.Parse(dt.Rows[i]["GradeID"].ToString());
                vo.GradeScore = int.Parse(dt.Rows[i]["GradeScore"].ToString());
                vo.GradeContent = dt.Rows[i]["GradeContent"].ToString();
                vo.FKGradeSkillID = int.Parse(dt.Rows[i]["FKGradeSkillID"].ToString());
                vo.FKGradeContentGuid = dt.Rows[i]["FKGradeContentGuid"].ToString();
                vo.GradeCreatetime = DateTime.Parse(dt.Rows[i]["GradeCreatetime"].ToString());
                vo.FKGradeUserID = int.Parse(dt.Rows[i]["FKGradeUserID"].ToString());
                //修改FKGradeResourceID
                vo.FKGradeResourceID = ResourceID;
                //根据参数starttime即开始录课时间以及记录中的GradeCreatetime即记录产生时间计算出记录产生时视频的时间点，然后记录到数据表的GradeAsfTime字段中

                if (vo.GradeCreatetime != null)
                {
                    TimeSpan ts = PowerCreator.LMS.Common.Utils.TimeUtils.TimeCompart(_starttime, vo.GradeCreatetime);
                    vo.GradeAsfTime = int.Parse((ts.Ticks / 10000000).ToString());
                }

                opGrade.UpdateGrade(vo);
            }
        }
    }

    private void UpdateResourceVideotime(int ResourceID)
    {
        VOTResource vo = new VOTResource();
        string sql = "ResourceID=" + ResourceID;
        vo = opCourse.LoadResource(ResourceID);
        string[] str = _videotime.Split(':');
        int videotime = 0;
        if (str.Length == 3)
        {
            if (int.Parse(str[0]) > 0)
                videotime = int.Parse(str[0]) * 60;
            videotime = videotime + int.Parse(str[1]);
        }
        vo.ResourceVideoTime = videotime;
        opCourse.UpdateResource(vo);
    }
}
